<template>
    <h2>用户登录</h2>
    <table class="table table-bordered">
        <tr>
            <td>用户名</td>
            <td><input type="text" v-model="state.name" /></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input type="password" v-model="state.pwd" /></td>
        </tr>
        <tr>
            <td></td>
            <td><input type="button" value="登录" @click="login" /></td>
        </tr>
    </table>
</template>

<script setup lang="ts">
import {ref, reactive, onMounted,toRefs} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import axios from 'axios';
import { useStore } from '../../store/user';
const useStores=useStore();
const router=useRouter();
const route=useRoute();
const data=reactive({
    state:{
        name:"",
        pwd:""
    },
    list:[]
})
let {state,list} =toRefs(data);
onMounted(()=>{
  
})

//用户登录
const login=()=>{
    axios({
        url:"/api/Finance/UserLogin",
        method:'get',
        params:state.value
    })
    .then(res=>{
        console.log(res);
        if(res.data.data==null)
        {
            alert('用户不存在');
            return;
        }
        else{
            useStores.userInfo=res.data.data;
            alert('登录成功');
           if(res.data.data.UT_Id==1)
           {
            router.push('adminFinanceList');
           }
           else{
            router.push('userFinanceList');
           }
        }
       
    })
}
</script>


<style>


</style>